﻿unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
  FMX.Layers3D, FMX.Controls3D, FMX.Gestures, FMX.Ani, FMX.TabControl,
  System.Rtti, Data.Bind.EngExt, FMX.Bind.DBEngExt, FMX.Bind.Grid,
  System.Bindings.Outputs, FMX.Bind.Editors, FMX.Grid, Data.Bind.Components,
  Data.Bind.Grid, Data.Bind.DBScope, FMX.Layouts, FMX.Edit, System.Math.Vectors,
  FMX.Types3D, FMX.Controls.Presentation;

type
  TForm1 = class(TForm)
    TabControl1: TTabControl;
    TabItem1: TTabItem;
    TabItem2: TTabItem;
    TabItem3: TTabItem;
    GestureManager1: TGestureManager;
    Camera1: TCamera;
    Camera2: TCamera;
    Light1: TLight;
    ProxyObject1: TProxyObject;
    Layout3D1: TLayout3D;
    Button1: TButton;
    RadioButton1: TRadioButton;
    GroupBox1: TGroupBox;
    CalloutPanel1: TCalloutPanel;
    Button2: TButton;
    CornerButton1: TCornerButton;
    ArcDial1: TArcDial;
    AniIndicator1: TAniIndicator;
    ColorAnimation1: TColorAnimation;
    Button3: TButton;
    BindSourceDB1: TBindSourceDB;
    BindingsList1: TBindingsList;
    Button4: TButton;
    BindSourceDB2: TBindSourceDB;
    BindSourceDB3: TBindSourceDB;
    Grid3: TGrid;
    LinkGridToDataSourceBindSourceDB32: TLinkGridToDataSource;
    Button6: TButton;
    Edit1: TEdit;
    Grid1: TGrid;
    LinkGridToDataSourceBindSourceDB2: TLinkGridToDataSource;
    lbl1: TLabel;
    bndxprsn1: TBindExpression;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure Button1Click(Sender: TObject);
    procedure TabControl1Gesture(Sender: TObject;
      const EventInfo: TGestureEventInfo; var Handled: Boolean);
    procedure FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
      Shift: TShiftState);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses
{$IFDEF ANDROID}
  FMX.Platform.Android,
{$ENDIF ANDROID}
{$R *.fmx}
  Unit3, u_database;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
{$IFDEF ANDROID}
  MainActivity.finish;
  Application.MainForm.DisposeOf; // 必不可少的
  halt(0);
{$ENDIF}
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  close;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  // 创建并显示窗体
  if not Assigned(Form3) then
    Form3 := TForm3.Create(Self);
  Form3.Show;

end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  database.fdquery1.close;
  database.fdquery1.SQL.Clear;
  database.fdquery1.SQL.Text := 'select * from syslogincfg';
  database.fdquery1.open;

  Edit1.Text := database.fdquery1.FieldList.FieldByName('susername')
    .AsString;
   Self.bndxprsn1.Evaluate;  { TODO : 生生死死 }
end;

procedure TForm1.Button6Click(Sender: TObject);
var
  csql: string;
begin
  csql := 'insert into syslogincfg(HostName,ServerPort,productCode,suserName) values (:HostName,:ServerPort,:productCode,:suserName)';

  database.qrytemp.close;
  database.qrytemp.SQL.Clear;
  database.qrytemp.SQL.add(csql);
  database.qrytemp.ParamByName('HostName').AsString := ('试试sd生');
  database.qrytemp.ParamByName('ServerPort').Value := ('213');
  database.qrytemp.ParamByName('productCode').Value := ('试试道sd生的');
  database.qrytemp.ParamByName('suserName').AsString := UTF8Encode('试试dg生的'); //AsAnsiString
  database.qrytemp.ExecSQL;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if MessageDlg('是否退出？', TMsgDlgType.mtConfirmation,
    [TMsgDlgBtn.mbOK, TMsgDlgBtn.mbCancel], -1) = mrOK then
    CanClose := true
  else
    CanClose := false;
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
  Shift: TShiftState);
begin
  { //如果是硬件的返回按钮
    if Key = vkHardwareBack then    //主键vkmenu
    begin

    //在特定的页面上，返回上一个页面
    if (TabControl1.ActiveTab = TabItem1) and (TabControl2.ActiveTab = TabItem6) then
    begin

    //指定页面
    TabControl2.ActiveTab = TabItem5;

    //已处理键盘的键值
    Key := 0;
    end;
    end; }
end;

procedure TForm1.TabControl1Gesture(Sender: TObject;
  const EventInfo: TGestureEventInfo; var Handled: Boolean);
begin
  // 识别事件的手势
  case EventInfo.GestureID of
    sgiLeft: // 由右向左滑动手指
      begin

        // 如果不是最后一个tab，则选择下一个tab
        if TabControl1.ActiveTab <> TabControl1.Tabs[TabControl1.TabCount - 1]
        then
          TabControl1.ActiveTab := TabControl1.Tabs[TabControl1.TabIndex + 1];
        Handled := true; // 已代码处理
      end;

    sgiRight: // 由左向右滑动手指
      begin

        // 如果不是第一个tab，则选取前一个tab
        if TabControl1.ActiveTab <> TabControl1.Tabs[0] then
          TabControl1.ActiveTab := TabControl1.Tabs[TabControl1.TabIndex - 1];
        Handled := true; // 已代码处理
      end;
  end;

end;

end.

(*
  七、安卓下对话框的标题和图标的汉化
  使用MessageDlg时，弹出的对话框标题和按钮是英文，显示的界面不友好，可按一下方式修改。
  找到XE5下的FMX.Consts.pas文件，修改
  { Dialog Strings }
  SMsgDlgWarning = '警告';
  SMsgDlgError = '错误';
  SMsgDlgInformation = '信息';
  SMsgDlgConfirm = '确认';
  SMsgDlgYes = '确定';
  SMsgDlgNo = '取消';
  SMsgDlgOK = '确定';
  SMsgDlgCancel = '取消';
  SMsgDlgHelp = 'Help';
  SMsgDlgHelpNone = 'No help available';
  SMsgDlgHelpHelp = 'Help';
  SMsgDlgAbort = '放弃';
  SMsgDlgRetry = '重试';
  SMsgDlgIgnore = '忽略';
  SMsgDlgAll = '全部';
  SMsgDlgNoToAll = 'No to All';
  SMsgDlgYesToAll = 'Yes to &All';
  SMsgDlgClose = '关闭';
  然后保存，新建一个手机Application，引用该文件，选择平台为安卓，编译后生成一个FMX.Consts.o文件，把文件拷贝到XE5文件加下的\lib\android\release或\lib\android\debug下，覆盖同名文件；这时你在编译你的手机程序，看下效果，弹出时显示的中文，呵比较友好。
*)
